<!DOCTYPE html>
<html class="theme theme-white">
<head>
<meta charset="utf-8">
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<meta name="Keywords"
          content="严振杰,严振杰的博客,严振杰的Gihutb,Yolana的博客,尤兰达,尤兰达的博客,Yolanda,达哥,NoHttp,NoHttp作者,NoHttp是什么,NoHttp下载,NoHttp官网,NoHttp汉化,,Java,Android,手机/移动开发"/>
		  <meta id="viewport" name="viewport"
          content="width=device-width; initial-scale=1.0; maximum-scale=1; user-scalable=no;"/>
<title>NoHttp</title>
<link href="https://www.zybuluo.com/static/assets/template-theme-white.css" rel="stylesheet" media="screen">
<style type="text/css">

#wmd-preview h1  {
    color: #0077bb; /* 将标题改为蓝色 */
}</style>
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>
</head>
<body class="theme theme-white">
<div id="wmd-preview" class="wmd-preview wmd-preview-full-reader">
<div class="md-section-divider"></div>
<div class="md-section-divider"></div>
<h1 data-anchor-id="lnqe" id="nohttp">NoHttp</h1>
<p data-anchor-id="hqfj"><img src="http://api.nohttp.net/image/nohttp_logo.svg" alt="NoHttp Logo" title=""></p>
<p data-anchor-id="rl0c">技术交流1群：46523908 <br>
技术交流2群：46505645 <br>
<a href="https://github.com/yanzhenjie/SkillGroupRule" target="_blank">群行为规范</a> <br>
</p>
<p data-anchor-id="kptb">
严振杰的博客：<a href="http://blog.csdn.net/yanzhenjie1003" target="_blank">http://blog.csdn.net/yanzhenjie1003</a> <br>
严振杰的Android直播视频下载：<a href="http://pan.baidu.com/s/1miEOtwG" target="_blank">http://pan.baidu.com/s/1miEOtwG</a>  </p>
<blockquote data-anchor-id="jolk" class="white-blockquote">
  <p>NoHttp，一个有情怀的框架。</p>
</blockquote><hr><div class="md-section-divider"></div>
<h2 data-anchor-id="g24b" id="nohttp主页和文档地址">NoHttp主页和文档地址</h2>
<p data-anchor-id="ria2">
NoHttp主页：<a href="http://www.nohttp.net" target="_blank">http://www.nohttp.net</a> <br>
NoHttp文档：<a href="http://doc.nohttp.net" target="_blank">http://doc.nohttp.net</a> <br>
NoHttp源码：<a href="https://github.com/yanzhenjie/NoHttp" target="_blank">https://github.com/yanzhenjie/NoHttp</a> <br>
文档还在继续完善，有问题可以加上面的群，或者发<a href="https://github.com/yanzhenjie/NoHttp/issues" target="_blank">issues</a>，或者直接发邮件给我：smallajax@foxmail.com。</p><div class="md-section-divider"></div><h2 data-anchor-id="oiab" id="使用方法">使用方法</h2><ul data-anchor-id="7yaw">
<li>Eclipse使用Jar包：<a href="https://github.com/yanzhenjie/NoHttp/blob/master/Jar/nohttp1.0.1.jar?raw=true" target="_blank">下载Jar包</a></li>
<li>AndroidStudio使用Gradle构建添加依赖（推荐）</li>
</ul><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="vrl6"><ol class="linenums"><li class="L0"><code class="language-groovy"><span class="pln">compile </span><span class="str">'com.yolanda.nohttp:nohttp:1.0.1'</span></code></li></ol></pre><ul data-anchor-id="jxy3">
</ul><div class="md-section-divider"></div><h2 data-anchor-id="f0of" id="下载demo">下载Demo</h2><p data-anchor-id="zra5"><a href="https://github.com/yanzhenjie/NoHttp/blob/master/nohttp_sample.apk?raw=true" target="_blank">下载演示Demo</a></p><div class="md-section-divider"></div><h2 data-anchor-id="n90w" id="nohttp特性">NoHttp特性</h2><p data-anchor-id="4yip">　　NoHttp实现了Http1.1（RFC2616），一个标准的Http框架。</p><ul data-anchor-id="ggxz">
<li>请求和下载都是队列，平均分配每个线程的资源，支持多个请求并发。</li>
<li>支持GET、POST、PUT、PATCH、HEAD、DELETE、OPTIONS、TRACE等全部（11种）Http请求协议。</li>
<li>支持基于POST、PUT、PATCH、DELETE的文件上传（Html表单原理）。</li>
<li>文件下载、上传下载、上传和下载的进度回调、错误回调等友好接口。</li>
<li>提供了五种数据缓存模式（详细看下文）。</li>
<li>支持取消某个请求、取消指定多个请求、取消所有请求。</li>
<li>支持自定义Request，利用NoHttp发型可以解析成你想要的任何数据格式（String、Json、JavaBean等）。</li>
<li>支持Session、Cookie的自动维持，App重启、关开机后还持续维持。</li>
<li>支持Https、自签名网站Https的访问、支持双向验证。</li>
</ul><div class="md-section-divider"></div><h3 data-anchor-id="9c0g" id="友好的调试模式">友好的调试模式</h3><p data-anchor-id="erxy">　　NoHttp提供了调试模式，打开后可以清晰的看到请求过程、怎么传递数据等，基本不用抓包。可以看到请求头、请求数据、响应头、Cookie等的过程。你也不用担心Log太多会让你眼花缭乱，想象不到的整洁。</p><div class="md-section-divider"></div><h3 data-anchor-id="1xkk" id="请求">请求</h3><blockquote data-anchor-id="ntij" class="white-blockquote">
  <ul>
  <li>支持请求String、Json、FastJson、Gson、Bitmap、JavaBean、XML等扩展。</li>
  <li>异步请求，拿到结果直接更新UI，支持同步请求。</li>
  </ul>
</blockquote><div class="md-section-divider"></div><h3 data-anchor-id="1hpw" id="多文件上传">多文件上传</h3><p data-anchor-id="hll7">　　所有下载均有进度回调、错误回调等友好的接口。</p><blockquote data-anchor-id="mq8t" class="white-blockquote">
  <ul>
  <li>大文件上传，不会发生OOM。</li>
  <li>多文件上传，多个key多个文件，一个key多个文件（<code>List&lt;File&gt;</code>）。</li>
  <li>支持File、InputStream、ByteArray、Bitmap，实现NoHttp的Binary接口，理论上任何东西都可以传。</li>
  <li>支持取消上传。</li>
  </ul>
</blockquote><div class="md-section-divider"></div><h3 data-anchor-id="hg8b" id="文件下载">文件下载</h3><blockquote data-anchor-id="ldzq" class="white-blockquote">
  <ul>
  <li>文件下载，支持多个文件同时下载，并且有进度回调、错误回调等。</li>
  <li>支持暂停继续下载，支持取消下载，支持断点续传。</li>
  <li>利用NoHttp的多文件下载可以做一个下载管理器。</li>
  </ul>
</blockquote><div class="md-section-divider"></div><h3 data-anchor-id="58ks" id="缓存模式">缓存模式</h3><blockquote data-anchor-id="6i6r" class="white-blockquote">
  <ul>
  <li>仅仅请求网络。</li>
  <li>仅仅读取缓存。</li>
  <li>标准Http协议缓存(比如响应码是304的情况)，需要服务器支持，如果服务器不支持就和普通请求一样。</li>
  <li>先请求网络，请求失败后返回缓存。</li>
  <li>先读取缓存，缓存不存在再请求网络。</li>
  </ul>
</blockquote><div class="md-section-divider"></div><h3 data-anchor-id="gw2a" id="取消请求">取消请求</h3><p data-anchor-id="tv80">　　所有取消都支持正在执行的请求。</p><blockquote data-anchor-id="njph" class="white-blockquote">
  <ul>
  <li>支持取消某个请求。</li>
  <li>支持取消用sign指定的几个请求。</li>
  <li>支持取消所有的请求。</li>
  </ul>
</blockquote><div class="md-section-divider"></div><h3 data-anchor-id="f2m9" id="请求自动维持cookie">请求自动维持Cookie</h3><blockquote data-anchor-id="3fsh" class="white-blockquote">
  <ul>
  <li>支持Session、Cookie、临时Cookie的位置。</li>
  <li>支持App重启、关机开机后继续持久化维持。</li>
  <li>提供了接口，允许开发者监听Cookie的变化，也可以改变某个Cookie的值。</li>
  </ul>
</blockquote><div class="md-section-divider"></div><h3 data-anchor-id="71o2" id="重定向">重定向</h3><blockquote data-anchor-id="y35t" class="white-blockquote">
  <ul>
  <li>对于Http301、302、303、307等重定向的支持。</li>
  <li>支持多级重定向嵌套。</li>
  <li>支持禁用重定向、NoHttp提供了操作重定向的接口。</li>
  </ul>
</blockquote><div class="md-section-divider"></div><h3 data-anchor-id="wbmp" id="代理">代理</h3><blockquote data-anchor-id="pxz6" class="white-blockquote">
  <ul>
  <li>标准的Java的Api，ProXy：指定代理的IP和Port。</li>
  <li>比如调试时代理到自己电脑进行抓包，比如用代理访问Google。</li>
  </ul>
</blockquote><div class="md-section-divider"></div><h2 data-anchor-id="viyr" id="一-请求">一. 请求</h2><div class="md-section-divider"></div><h3 data-anchor-id="7d4a" id="string请求">String请求</h3><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="mops"><ol class="linenums"><li class="L0"><code class="language-java"><span class="com">// String 请求对象</span></code></li><li class="L1"><code class="language-java"><span class="typ">Request</span><span class="pun">&lt;</span><span class="typ">String</span><span class="pun">&gt;</span><span class="pln"> request </span><span class="pun">=</span><span class="pln"> </span><span class="typ">NoHttp</span><span class="pun">.</span><span class="pln">createStringRequest</span><span class="pun">(</span><span class="pln">url</span><span class="pun">,</span><span class="pln"> requestMethod</span><span class="pun">);</span></code></li></ol></pre><div class="md-section-divider"></div><h3 data-anchor-id="ivzf" id="json请求">Json请求</h3><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="3t00"><ol class="linenums"><li class="L0"><code class="language-java"><span class="com">// JsonObject</span></code></li><li class="L1"><code class="language-java"><span class="typ">Request</span><span class="pun">&lt;</span><span class="typ">JSONObject</span><span class="pun">&gt;</span><span class="pln"> request </span><span class="pun">=</span><span class="pln"> </span><span class="typ">NoHttp</span><span class="pun">.</span><span class="pln">createJsonObjectRequest</span><span class="pun">(</span><span class="pln">url</span><span class="pun">,</span><span class="pln"> reqeustMethod</span><span class="pun">);</span></code></li><li class="L2"><code class="language-java"><span class="pun">...</span></code></li><li class="L3"><code class="language-java"><span class="com">// JsonArray</span></code></li><li class="L4"><code class="language-java"><span class="typ">Request</span><span class="pun">&lt;</span><span class="typ">JSONArray</span><span class="pun">&gt;</span><span class="pln"> request </span><span class="pun">=</span><span class="pln"> </span><span class="typ">NoHttp</span><span class="pun">.</span><span class="pln">createJsonArrayRequest</span><span class="pun">(</span><span class="pln">url</span><span class="pun">,</span><span class="pln"> reqeustMethod</span><span class="pun">);</span></code></li></ol></pre><div class="md-section-divider"></div><h3 data-anchor-id="dbtt" id="bitmap请求">Bitmap请求</h3><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="zxd8"><ol class="linenums"><li class="L0"><code class="language-java"><span class="typ">Request</span><span class="pun">&lt;</span><span class="typ">Bitmap</span><span class="pun">&gt;</span><span class="pln"> request </span><span class="pun">=</span><span class="pln"> </span><span class="typ">NoHttp</span><span class="pun">.</span><span class="pln">createImageRequest</span><span class="pun">(</span><span class="pln">url</span><span class="pun">,</span><span class="pln"> requestMethod</span><span class="pun">);</span></code></li></ol></pre><div class="md-section-divider"></div><h3 data-anchor-id="q0dz" id="添加参数">添加参数</h3><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="6wrg"><ol class="linenums"><li class="L0"><code class="language-java"><span class="typ">Request</span><span class="pun">&lt;</span><span class="typ">JSONObject</span><span class="pun">&gt;</span><span class="pln"> request </span><span class="pun">=</span><span class="pln"> </span><span class="pun">...</span></code></li><li class="L1"><code class="language-java"><span class="pln">request</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="str">"name"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"yoldada"</span><span class="pun">);</span><span class="com">// String类型</span></code></li><li class="L2"><code class="language-java"><span class="pln">request</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="str">"age"</span><span class="pun">,</span><span class="pln"> </span><span class="lit">18</span><span class="pun">);</span><span class="com">// int类型</span></code></li><li class="L3"><code class="language-java"><span class="pln">request</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="str">"sex"</span><span class="pun">,</span><span class="pln"> </span><span class="str">'0'</span><span class="pun">)</span><span class="com">// char类型</span></code></li><li class="L4"><code class="language-java"><span class="pln">request</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="str">"time"</span><span class="pun">,</span><span class="pln"> </span><span class="lit">16346468473154</span><span class="pun">);</span><span class="pln"> </span><span class="com">// long类型</span></code></li><li class="L5"><code class="language-java"><span class="pun">...</span></code></li></ol></pre><div class="md-section-divider"></div><h3 data-anchor-id="wc47" id="添加到队列">添加到队列</h3><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="31p2"><ol class="linenums"><li class="L0"><code class="language-java"><span class="typ">RequestQueue</span><span class="pln"> requestQueue </span><span class="pun">=</span><span class="pln"> </span><span class="typ">NoHttp</span><span class="pun">.</span><span class="pln">createRequestQueue</span><span class="pun">();</span></code></li><li class="L1"><code class="language-java"><span class="com">// 或者传一个并发值，允许三个请求同时并发</span></code></li><li class="L2"><code class="language-java"><span class="com">// RequestQueue requestQueue = NoHttp.createRequestQueue(3);</span></code></li><li class="L3"><code class="language-java"></code></li><li class="L4"><code class="language-java"><span class="com">// 发起请求</span></code></li><li class="L5"><code class="language-java"><span class="pln">requestQueue</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">what</span><span class="pun">,</span><span class="pln"> request</span><span class="pun">,</span><span class="pln"> responseListener</span><span class="pun">);</span></code></li></ol></pre><p data-anchor-id="mklz">　　上面添加到队列时有一个what，这个what会在<code>responseLisetener</code>响应时回调给开发者，所以我们可以用一个<code>responseLisetener</code>接受多个请求的响应，用what来区分结果。而不用像有的框架一样，每一个请求都要new一个回调。</p><div class="md-section-divider"></div><h3 data-anchor-id="0jl0" id="同步请求">同步请求</h3><p data-anchor-id="ns6k">　　在当前线程发起请求，在线程这么使用。</p><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="9387"><ol class="linenums"><li class="L0"><code class="language-java"><span class="typ">Request</span><span class="pun">&lt;</span><span class="typ">String</span><span class="pun">&gt;</span><span class="pln"> request </span><span class="pun">=</span><span class="pln"> </span><span class="pun">...</span></code></li><li class="L1"><code class="language-java"><span class="typ">Response</span><span class="pun">&lt;</span><span class="typ">String</span><span class="pun">&gt;</span><span class="pln"> response </span><span class="pun">=</span><span class="pln"> </span><span class="typ">NoHttp</span><span class="pun">.</span><span class="pln">startRequestSync</span><span class="pun">(</span><span class="pln">request</span><span class="pun">);</span></code></li><li class="L2"><code class="language-java"><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">response</span><span class="pun">.</span><span class="pln">isSucceed</span><span class="pun">())</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L3"><code class="language-java"><span class="pln">    </span><span class="com">// 请求成功</span></code></li><li class="L4"><code class="language-java"><span class="pun">}</span><span class="pln"> </span><span class="kwd">else</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L5"><code class="language-java"><span class="pln">    </span><span class="com">// 请求失败</span></code></li><li class="L6"><code class="language-java"><span class="pun">}</span></code></li></ol></pre><div class="md-section-divider"></div><h2 data-anchor-id="n9hz" id="二-文件上传">二. 文件上传</h2><p data-anchor-id="a8a5">　　支持多文件上传，多个key多个文件，一个key多个文件（<code>List&lt;File&gt;</code>）。支持File、InputStream、ByteArray、Bitmap，实现NoHttp的Binary接口，理论上任何东西都可以传。</p><div class="md-section-divider"></div><h3 data-anchor-id="ccf5" id="单个文件">单个文件</h3><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="pio7"><ol class="linenums"><li class="L0"><code class="language-java"><span class="typ">Request</span><span class="pun">&lt;</span><span class="typ">String</span><span class="pun">&gt;</span><span class="pln"> request </span><span class="pun">=</span><span class="pln"> </span><span class="pun">...</span></code></li><li class="L1"><code class="language-java"><span class="pln">request</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="str">"file"</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">FileBinary</span><span class="pun">(</span><span class="pln">file</span><span class="pun">));</span></code></li></ol></pre><div class="md-section-divider"></div><h3 data-anchor-id="qdar" id="上传多个文件多个key多个文件形式">上传多个文件、多个Key多个文件形式</h3><p data-anchor-id="tvog">　　这里可以添加各种形式的文件，File、Bitmap、InputStream、ByteArray：</p><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="vn0h"><ol class="linenums"><li class="L0"><code class="language-java"><span class="typ">Request</span><span class="pun">&lt;</span><span class="typ">String</span><span class="pun">&gt;</span><span class="pln"> request </span><span class="pun">=</span><span class="pln"> </span><span class="pun">...</span></code></li><li class="L1"><code class="language-java"><span class="pln">request</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="str">"file1"</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">FileBinary</span><span class="pun">(</span><span class="typ">File</span><span class="pun">));</span></code></li><li class="L2"><code class="language-java"><span class="pln">request</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="str">"file2"</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">FileBinary</span><span class="pun">(</span><span class="typ">File</span><span class="pun">));</span></code></li><li class="L3"><code class="language-java"><span class="pln">request</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="str">"file3"</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">InputStreamBinary</span><span class="pun">(</span><span class="typ">InputStream</span><span class="pun">));</span></code></li><li class="L4"><code class="language-java"><span class="pln">request</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="str">"file4"</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">ByteArrayBinary</span><span class="pun">(</span><span class="kwd">byte</span><span class="pun">[]));</span></code></li><li class="L5"><code class="language-java"><span class="pln">request</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="str">"file5"</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">BitmapStreamBinary</span><span class="pun">(</span><span class="typ">Bitmap</span><span class="pun">));</span></code></li></ol></pre><div class="md-section-divider"></div><h3 data-anchor-id="nh32" id="上传多个文件一个key多个文件形式">上传多个文件、一个Key多个文件形式</h3><p data-anchor-id="an2p">　　用同一个key添加，如果请求方法是POST、PUT、PATCH、DELETE，同一个key不会被覆盖。</p><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="e26q"><ol class="linenums"><li class="L0"><code class="language-java"><span class="typ">Request</span><span class="pun">&lt;</span><span class="typ">String</span><span class="pun">&gt;</span><span class="pln"> request </span><span class="pun">=</span><span class="pln"> </span><span class="pun">...</span></code></li><li class="L1"><code class="language-java"><span class="pln">fileList</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="str">"image"</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">FileBinary</span><span class="pun">(</span><span class="typ">File</span><span class="pun">));</span></code></li><li class="L2"><code class="language-java"><span class="pln">fileList</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="str">"image"</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">InputStreamBinary</span><span class="pun">(</span><span class="typ">InputStream</span><span class="pun">));</span></code></li><li class="L3"><code class="language-java"><span class="pln">fileList</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="str">"image"</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">ByteArrayBinary</span><span class="pun">(</span><span class="kwd">byte</span><span class="pun">[]));</span></code></li><li class="L4"><code class="language-java"><span class="pln">fileList</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="str">"image"</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">BitmapStreamBinary</span><span class="pun">(</span><span class="typ">Bitmap</span><span class="pun">));</span></code></li></ol></pre><p data-anchor-id="2t5x">　　或者：</p><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="nwfy"><ol class="linenums"><li class="L0"><code class="language-java"><span class="typ">Request</span><span class="pun">&lt;</span><span class="typ">String</span><span class="pun">&gt;</span><span class="pln"> request </span><span class="pun">=</span><span class="pln"> </span><span class="pun">...</span></code></li><li class="L1"><code class="language-java"></code></li><li class="L2"><code class="language-java"><span class="typ">List</span><span class="pun">&lt;</span><span class="typ">Binary</span><span class="pun">&gt;</span><span class="pln"> fileList </span><span class="pun">=</span><span class="pln"> </span><span class="pun">...</span></code></li><li class="L3"><code class="language-java"><span class="pln">fileList</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="kwd">new</span><span class="pln"> </span><span class="typ">FileBinary</span><span class="pun">(</span><span class="typ">File</span><span class="pun">));</span></code></li><li class="L4"><code class="language-java"><span class="pln">fileList</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="kwd">new</span><span class="pln"> </span><span class="typ">InputStreamBinary</span><span class="pun">(</span><span class="typ">InputStream</span><span class="pun">));</span></code></li><li class="L5"><code class="language-java"><span class="pln">fileList</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="kwd">new</span><span class="pln"> </span><span class="typ">ByteArrayBinary</span><span class="pun">(</span><span class="kwd">byte</span><span class="pun">[]));</span></code></li><li class="L6"><code class="language-java"><span class="pln">fileList</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="kwd">new</span><span class="pln"> </span><span class="typ">BitmapStreamBinary</span><span class="pun">(</span><span class="typ">Bitmap</span><span class="pun">));</span></code></li><li class="L7"><code class="language-java"><span class="pln">request</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="str">"file1"</span><span class="pun">,</span><span class="pln"> fileList</span><span class="pun">);</span></code></li></ol></pre><div class="md-section-divider"></div><h2 data-anchor-id="bsaf" id="三-下载文件">三. 下载文件</h2><p data-anchor-id="ogtl">　　因为下载文件代码比较多，这里贴关键部分，具体的请参考sample。</p><div class="md-section-divider"></div><h3 data-anchor-id="dbx0" id="发起下载请求">发起下载请求</h3><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="w33h"><ol class="linenums"><li class="L0"><code class="language-java"><span class="com">//下载文件</span></code></li><li class="L1"><code class="language-java"><span class="pln">downloadRequest </span><span class="pun">=</span><span class="pln"> </span><span class="typ">NoHttp</span><span class="pun">.</span><span class="pln">createDownloadRequest</span><span class="pun">...</span></code></li><li class="L2"><code class="language-java"><span class="com">// what 区分下载</span></code></li><li class="L3"><code class="language-java"><span class="com">// downloadRequest 下载请求对象</span></code></li><li class="L4"><code class="language-java"><span class="com">// downloadListener 下载监听</span></code></li><li class="L5"><code class="language-java"><span class="typ">CallServer</span><span class="pun">.</span><span class="pln">getDownloadInstance</span><span class="pun">().</span><span class="pln">add</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> downloadRequest</span><span class="pun">,</span><span class="pln"> downloadListener</span><span class="pun">);</span></code></li></ol></pre><div class="md-section-divider"></div><h3 data-anchor-id="stql" id="暂停或者停止下载">暂停或者停止下载</h3><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="163b"><ol class="linenums"><li class="L0"><code class="language-java"><span class="pln">downloadRequest</span><span class="pun">.</span><span class="pln">cancel</span><span class="pun">();</span></code></li></ol></pre><div class="md-section-divider"></div><h3 data-anchor-id="14k3" id="监听下载过程">监听下载过程</h3><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="p479"><ol class="linenums"><li class="L0"><code class="language-java"><span class="kwd">private</span><span class="pln"> </span><span class="typ">DownloadListener</span><span class="pln"> downloadListener </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">DownloadListener</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L1"><code class="language-java"><span class="pln">    </span><span class="lit">@Override</span></code></li><li class="L2"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onStart</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> what</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">boolean</span><span class="pln"> resume</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> preLenght</span><span class="pun">,</span><span class="pln"> </span><span class="typ">Headers</span><span class="pln"> header</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> count</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L3"><code class="language-java"><span class="pln">        </span><span class="com">// 下载开始</span></code></li><li class="L4"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L5"><code class="language-java"></code></li><li class="L6"><code class="language-java"><span class="pln">    </span><span class="lit">@Override</span></code></li><li class="L7"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onProgress</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> what</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> progress</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> downCount</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L8"><code class="language-java"><span class="pln">        </span><span class="com">// 更新下载进度</span></code></li><li class="L9"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L0"><code class="language-java"></code></li><li class="L1"><code class="language-java"><span class="pln">    </span><span class="lit">@Override</span></code></li><li class="L2"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onFinish</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> what</span><span class="pun">,</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> filePath</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L3"><code class="language-java"><span class="pln">        </span><span class="com">// 下载完成</span></code></li><li class="L4"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L5"><code class="language-java"></code></li><li class="L6"><code class="language-java"><span class="pln">    </span><span class="lit">@Override</span></code></li><li class="L7"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onDownloadError</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> what</span><span class="pun">,</span><span class="pln"> </span><span class="typ">StatusCode</span><span class="pln"> code</span><span class="pun">,</span><span class="pln"> </span><span class="typ">CharSequence</span><span class="pln"> message</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L8"><code class="language-java"><span class="pln">        </span><span class="com">// 下载发生错误</span></code></li><li class="L9"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L0"><code class="language-java"></code></li><li class="L1"><code class="language-java"><span class="pln">    </span><span class="lit">@Override</span></code></li><li class="L2"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onCancel</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> what</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L3"><code class="language-java"><span class="pln">        </span><span class="com">// 下载被取消或者暂停</span></code></li><li class="L4"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L5"><code class="language-java"><span class="pun">};</span></code></li></ol></pre><div class="md-section-divider"></div><h2 data-anchor-id="710c" id="四-缓存模式">四. 缓存模式</h2><div class="md-section-divider"></div><h3 data-anchor-id="6iof" id="1-http标准协议的缓存比如响应码是304时">1. Http标准协议的缓存，比如响应码是304时</h3><p data-anchor-id="i86h">　　NoHttp本身是实现了RFC2616，所以这里不用设置或者设置为DEFAULT。</p><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="rztc"><ol class="linenums"><li class="L0"><code class="language-java"><span class="typ">Request</span><span class="pun">&lt;</span><span class="typ">JSONObject</span><span class="pun">&gt;</span><span class="pln"> request </span><span class="pun">=</span><span class="pln"> </span><span class="typ">NoHttp</span><span class="pun">.</span><span class="pln">createJsonObjectRequest</span><span class="pun">(</span><span class="pln">url</span><span class="pun">);</span></code></li><li class="L1"><code class="language-java"><span class="pln">request</span><span class="pun">.</span><span class="pln">setCacheMode</span><span class="pun">(</span><span class="typ">CacheMode</span><span class="pun">.</span><span class="pln">DEFAULT</span><span class="pun">);</span></code></li></ol></pre><div class="md-section-divider"></div><h3 data-anchor-id="s485" id="2-当请求服务器失败的时候读取缓存">2. 当请求服务器失败的时候，读取缓存</h3><p data-anchor-id="fcpf">　　请求服务器成功则返回服务器数据，如果请求服务器失败，读取缓存数据返回。</p><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="w49h"><ol class="linenums"><li class="L0"><code class="language-java"><span class="typ">Request</span><span class="pun">&lt;</span><span class="typ">JSONObject</span><span class="pun">&gt;</span><span class="pln"> request </span><span class="pun">=</span><span class="pln"> </span><span class="typ">NoHttp</span><span class="pun">.</span><span class="pln">createJsonObjectRequest</span><span class="pun">(</span><span class="pln">url</span><span class="pun">);</span></code></li><li class="L1"><code class="language-java"><span class="pln">request</span><span class="pun">.</span><span class="pln">setCacheMode</span><span class="pun">(</span><span class="typ">CacheMode</span><span class="pun">.</span><span class="pln">REQUEST_NETWORK_FAILED_READ_CACHE</span><span class="pun">);</span></code></li></ol></pre><div class="md-section-divider"></div><h3 data-anchor-id="4yt6" id="3-如果发现有缓存直接成功没有缓存才请求服务器">3. 如果发现有缓存直接成功，没有缓存才请求服务器</h3><p data-anchor-id="6z0k">　　我们知道ImageLoader的核心除了内存优化外，剩下一个就是发现把内地有图片则直接使用，没有则请求服务器，所以NoHttp这一点非常使用做一个ImageLoader。 <br>
　　如果没有缓存才去请求服务器，否则使用缓存：</p><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="hane"><ol class="linenums"><li class="L0"><code class="language-java"><span class="typ">Request</span><span class="pun">&lt;</span><span class="typ">JSONObject</span><span class="pun">&gt;</span><span class="pln"> request </span><span class="pun">=</span><span class="pln"> </span><span class="typ">NoHttp</span><span class="pun">.</span><span class="pln">createJsonObjectRequest</span><span class="pun">(</span><span class="pln">url</span><span class="pun">);</span></code></li><li class="L1"><code class="language-java"><span class="com">// 非标准Http协议，改变缓存模式为IF_NONE_CACHE_REQUEST_NETWORK</span></code></li><li class="L2"><code class="language-java"><span class="pln">request</span><span class="pun">.</span><span class="pln">setCacheMode</span><span class="pun">(</span><span class="typ">CacheMode</span><span class="pun">.</span><span class="pln">IF_NONE_CACHE_REQUEST_NETWORK</span><span class="pun">);</span></code></li></ol></pre><p data-anchor-id="xxdm">　　请求图片，缓存图片：</p><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="sso9"><ol class="linenums"><li class="L0"><code class="language-java"><span class="typ">Request</span><span class="pun">&lt;</span><span class="typ">Bitmap</span><span class="pun">&gt;</span><span class="pln"> request </span><span class="pun">=</span><span class="pln"> </span><span class="typ">NoHttp</span><span class="pun">.</span><span class="pln">createImageRequest</span><span class="pun">(</span><span class="pln">imageUrl</span><span class="pun">);</span></code></li><li class="L1"><code class="language-java"><span class="pln">request</span><span class="pun">.</span><span class="pln">setCacheMode</span><span class="pun">(</span><span class="typ">CacheMode</span><span class="pun">.</span><span class="pln">IF_NONE_CACHE_REQUEST_NETWORK</span><span class="pun">);</span></code></li></ol></pre><div class="md-section-divider"></div><h3 data-anchor-id="ket3" id="4-仅仅请求网络">4. 仅仅请求网络</h3><p data-anchor-id="shtd">　　这里不会读取缓存，也不会使用Http304：</p><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="wyl6"><ol class="linenums"><li class="L0"><code class="language-java"><span class="typ">Request</span><span class="pun">&lt;</span><span class="typ">Bitmap</span><span class="pun">&gt;</span><span class="pln"> request </span><span class="pun">=</span><span class="pln"> </span><span class="typ">NoHttp</span><span class="pun">.</span><span class="pln">createImageRequest</span><span class="pun">(</span><span class="pln">imageUrl</span><span class="pun">);</span></code></li><li class="L1"><code class="language-java"><span class="pln">request</span><span class="pun">.</span><span class="pln">setCacheMode</span><span class="pun">(</span><span class="typ">CacheMode</span><span class="pun">.</span><span class="pln">ONLY_REQUEST_NETWORK</span><span class="pun">);</span></code></li><li class="L2"><code class="language-java"><span class="pun">...</span></code></li></ol></pre><div class="md-section-divider"></div><h3 data-anchor-id="mh6k" id="5-仅仅读取缓存">5. 仅仅读取缓存</h3><p data-anchor-id="h63l">　　如果没有缓存才去请求服务器，否则使用缓存，缓存图片演示：</p><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="wjlw"><ol class="linenums"><li class="L0"><code class="language-java"><span class="typ">Request</span><span class="pun">&lt;</span><span class="typ">Bitmap</span><span class="pun">&gt;</span><span class="pln"> request </span><span class="pun">=</span><span class="pln"> </span><span class="typ">NoHttp</span><span class="pun">.</span><span class="pln">createImageRequest</span><span class="pun">(</span><span class="pln">imageUrl</span><span class="pun">);</span></code></li><li class="L1"><code class="language-java"><span class="pln">request</span><span class="pun">.</span><span class="pln">setCacheMode</span><span class="pun">(</span><span class="typ">CacheMode</span><span class="pun">.</span><span class="pln">ONLY_READ_CACHE</span><span class="pun">);</span></code></li></ol></pre><div class="md-section-divider"></div><h2 data-anchor-id="y06w" id="五-取消请求">五. 取消请求</h2><div class="md-section-divider"></div><h3 data-anchor-id="mm8n" id="取消单个请求">取消单个请求</h3><p data-anchor-id="moem">　　直接调用请求对象的cancel方法。</p><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="3zbx"><ol class="linenums"><li class="L0"><code class="language-java"><span class="pln">request</span><span class="pun">.</span><span class="pln">cancel</span><span class="pun">();</span></code></li></ol></pre><div class="md-section-divider"></div><h3 data-anchor-id="1ww4" id="从队列中取消指定的请求">从队列中取消指定的请求</h3><p data-anchor-id="493x">　　给请求set一个sign，取消的时候调用队列的cancelBySign就可以取消掉所有指定这个sign的请求。</p><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="8j61"><ol class="linenums"><li class="L0"><code class="language-java"><span class="pln">request</span><span class="pun">.</span><span class="pln">setCancelSign</span><span class="pun">(</span><span class="pln">sign</span><span class="pun">);</span></code></li><li class="L1"><code class="language-java"><span class="pun">...</span></code></li><li class="L2"><code class="language-java"><span class="pln">queue</span><span class="pun">.</span><span class="pln">cancelBySign</span><span class="pun">(</span><span class="pln">sign</span><span class="pun">);</span></code></li></ol></pre><div class="md-section-divider"></div><h3 data-anchor-id="hs67" id="取消队列中所有请求">取消队列中所有请求</h3><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="bbyl"><ol class="linenums"><li class="L0"><code class="language-java"><span class="pln">queue</span><span class="pun">.</span><span class="pln">cancelAll</span><span class="pun">();</span></code></li></ol></pre><div class="md-section-divider"></div><h3 data-anchor-id="qaih" id="停止队列">停止队列</h3><p data-anchor-id="rk97">　　队列停止后再添加请求到队列后，请求不会被执行。</p><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="7ktp"><ol class="linenums"><li class="L0"><code class="language-java"><span class="typ">RequestQueue</span><span class="pln"> queue </span><span class="pun">=</span><span class="pln"> </span><span class="typ">NoHttp</span><span class="pun">.</span><span class="pln">newRequestQueue</span><span class="pun">();</span></code></li><li class="L1"><code class="language-java"><span class="pun">...</span></code></li><li class="L2"><code class="language-java"><span class="pln">queue</span><span class="pun">.</span><span class="pln">stop</span><span class="pun">();</span></code></li></ol></pre><div class="md-section-divider"></div><h2 data-anchor-id="d24d" id="六-自定义请求类型-fastjsonrequest">六. 自定义请求类型: FastJsonRequest</h2><div class="md-section-divider"></div><h3 data-anchor-id="65il" id="定义请求对象">定义请求对象</h3><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="l4tp"><ol class="linenums"><li class="L0"><code class="language-java"><span class="kwd">public</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">FastJsonRequest</span><span class="pln"> </span><span class="kwd">extends</span><span class="pln"> </span><span class="typ">RestRequestor</span><span class="pun">&lt;</span><span class="typ">JSONObject</span><span class="pun">&gt;</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L1"><code class="language-java"></code></li><li class="L2"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="typ">FastJsonRequest</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> url</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L3"><code class="language-java"><span class="pln">        </span><span class="kwd">super</span><span class="pun">(</span><span class="pln">url</span><span class="pun">);</span></code></li><li class="L4"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L5"><code class="language-java"></code></li><li class="L6"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="typ">FastJsonRequest</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> url</span><span class="pun">,</span><span class="pln"> </span><span class="typ">RequestMethod</span><span class="pln"> requestMethod</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L7"><code class="language-java"><span class="pln">        </span><span class="kwd">super</span><span class="pun">(</span><span class="pln">url</span><span class="pun">,</span><span class="pln"> requestMethod</span><span class="pun">);</span></code></li><li class="L8"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L9"><code class="language-java"></code></li><li class="L0"><code class="language-java"><span class="pln">    </span><span class="lit">@Override</span></code></li><li class="L1"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="typ">JSONObject</span><span class="pln"> parseResponse</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> url</span><span class="pun">,</span><span class="pln"> </span><span class="typ">Headers</span><span class="pln"> headers</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">byte</span><span class="pun">[]</span><span class="pln"> responseBody</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L2"><code class="language-java"><span class="pln">        </span><span class="typ">String</span><span class="pln"> result </span><span class="pun">=</span><span class="pln"> </span><span class="typ">StringRequest</span><span class="pun">.</span><span class="pln">parseResponseString</span><span class="pun">(</span><span class="pln">url</span><span class="pun">,</span><span class="pln"> headers</span><span class="pun">,</span><span class="pln"> responseBody</span><span class="pun">);</span></code></li><li class="L3"><code class="language-java"><span class="pln">        </span><span class="typ">JSONObject</span><span class="pln"> jsonObject </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">null</span><span class="pun">;</span></code></li><li class="L4"><code class="language-java"><span class="pln">        </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(!</span><span class="typ">TextUtils</span><span class="pun">.</span><span class="pln">isEmpty</span><span class="pun">(</span><span class="pln">result</span><span class="pun">))</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L5"><code class="language-java"><span class="pln">            jsonObject </span><span class="pun">=</span><span class="pln"> JSON</span><span class="pun">.</span><span class="pln">parseObject</span><span class="pun">(</span><span class="pln">result</span><span class="pun">);</span></code></li><li class="L6"><code class="language-java"><span class="pln">        </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">else</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L7"><code class="language-java"><span class="pln">            </span><span class="com">// 这里默认的错误可以定义为你们自己的数据格式</span></code></li><li class="L8"><code class="language-java"><span class="pln">            jsonObject </span><span class="pun">=</span><span class="pln"> JSON</span><span class="pun">.</span><span class="pln">toJSON</span><span class="pun">(</span><span class="str">"{}"</span><span class="pun">);</span></code></li><li class="L9"><code class="language-java"><span class="pln">        </span><span class="pun">}</span></code></li><li class="L0"><code class="language-java"><span class="pln">        </span><span class="kwd">return</span><span class="pln"> jsonObject</span><span class="pun">;</span></code></li><li class="L1"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L2"><code class="language-java"></code></li><li class="L3"><code class="language-java"><span class="pln">    </span><span class="lit">@Override</span></code></li><li class="L4"><code class="language-java"><span class="pln">    </span><span class="kwd">public</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> getAccept</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L5"><code class="language-java"><span class="pln">        </span><span class="com">// 告诉服务器你接受什么类型的数据</span></code></li><li class="L6"><code class="language-java"><span class="pln">        </span><span class="kwd">return</span><span class="pln"> </span><span class="str">"application/json"</span><span class="pun">;</span></code></li><li class="L7"><code class="language-java"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L8"><code class="language-java"><span class="pun">}</span></code></li></ol></pre><div class="md-section-divider"></div><h3 data-anchor-id="yo1z" id="b-使用自定义请求-和nohttp默认请求没有区别的哦">b. 使用自定义请求-和NoHttp默认请求没有区别的哦</h3><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="n0ct"><ol class="linenums"><li class="L0"><code class="language-java"><span class="typ">Request</span><span class="pun">&lt;</span><span class="typ">JSONObject</span><span class="pun">&gt;</span><span class="pln"> mRequest </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">FastJsonRequest</span><span class="pun">(</span><span class="pln">url</span><span class="pun">,</span><span class="pln"> requestMethod</span><span class="pun">);</span></code></li><li class="L1"><code class="language-java"><span class="pln">queue</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">what</span><span class="pun">,</span><span class="pln"> mRequest</span><span class="pun">,</span><span class="pln"> responseListener</span><span class="pun">);</span></code></li></ol></pre><div class="md-section-divider"></div><h2 data-anchor-id="muy2" id="七-混淆">七. 混淆</h2><div class="md-section-divider"></div><h3 data-anchor-id="btkr" id="需要知道的">需要知道的</h3><pre data-anchor-id="2pgx"><code>NoHttp全部的类都可以混淆。
</code></pre><p data-anchor-id="2lkc">　　NoHttp1.0.0使用了leve23的api，所以打包的时候要用leve23才行。 <br>
　　NoHttp1.0.1使用了反射调用了高级或者低级的api，所以只要是leve9以上的sdk都可以编译。</p><div class="md-section-divider"></div><h3 data-anchor-id="ymp4" id="如果你非要keep">如果你非要keep</h3><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="k8db"><ol class="linenums"><li class="L0"><code class="language-text"><span class="com">#okhttputils</span></code></li><li class="L1"><code class="language-text"><span class="pun">-</span><span class="pln">dontwarn com</span><span class="pun">.</span><span class="pln">yolanda</span><span class="pun">.</span><span class="pln">nohttp</span><span class="pun">.**</span></code></li><li class="L2"><code class="language-text"><span class="pun">-</span><span class="pln">keep </span><span class="kwd">class</span><span class="pln"> com</span><span class="pun">.</span><span class="pln">yolanda</span><span class="pun">.</span><span class="pln">nohttp</span><span class="pun">.**{*;}</span></code></li></ol></pre></div>
</body>
</html>